/*
 * @Author: liuxinyea
 * @Date: 2024-08-12 22:03:57
 * @LastEditors: liuxinyea
 * @LastEditTime: 2024-08-12 22:49:19
 * @Description: 描述
 */
import { _decorator, animation, CCInteger, Component, find, instantiate, Node, Prefab, Vec3 } from 'cc';
import { Plant } from '../Plant';
import { PlantType } from '../Glabol';
const { ccclass, property } = _decorator;

@ccclass('PeaShooter')
export class PeaShooter extends Plant {
    public plantType: PlantType = PlantType.PeaShooter;
    @property(CCInteger)
    shootDuration: number = 1;
    private shootTimer: number = 0;
    private deltaTime: number
    private anim: animation.AnimationController;
    @property(Prefab)
    bulletPrefab: Prefab = null;
    protected onLoad(): void {
        this.anim = this.getComponent(animation.AnimationController);
    }
    update(deltaTime: number): void {
        super.update(deltaTime);
        this.deltaTime = deltaTime;
    }
    // 种下去之后再激活
    enableUpdate() {
        super.enableUpdate()
        this.shootTimer += this.deltaTime;
        if (this.shootTimer >= this.shootDuration) {
            this.shoot();
            this.shootTimer = 0;
        }
    }
    shoot() {
        console.log("shoot");
        const bullet = instantiate(this.bulletPrefab)
        bullet.setPosition(this.node.position)
        bullet.position.add(new Vec3(35, 18, 0))

        bullet.parent = find("Canvas/ForGround")
    }
}

